package cn.com.nes.site.service.equipment.archives;

import cn.com.nes.common.annotation.CtceTransactional;
import cn.com.nes.common.exception.BusinessException;
import cn.com.nes.common.exception.IllegalBusinessException;
import cn.com.nes.common.util.DESUtils;
import cn.com.nes.common.util.Globals;
import cn.com.nes.common.util.OssUtil;
import cn.com.nes.mybatis.callcenter.mapper.TXzqhMapper;
import cn.com.nes.mybatis.ctce.entity.TSbazdd;
import cn.com.nes.mybatis.ctce.entity.TSbcj;
import cn.com.nes.mybatis.ctce.entity.TSblx;
import cn.com.nes.mybatis.ctce.mapper.TSbazddMapper;
import cn.com.nes.mybatis.ctce.mapper.TSbcjMapper;
import cn.com.nes.mybatis.ctce.mapper.TSblxMapper;
import cn.com.nes.mybatis.ctce.mapper.TWxsbMapper;
import cn.com.nes.site.entity.bo.DeviceSaveBo;
import cn.com.nes.site.entity.bo.ctce.CtceEquipmentArchivesBo;
import cn.com.nes.site.service.project.dto.*;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.*;


/**
 * 清洁取暖设备档案处理类
 */
@Slf4j
@Service
public class CtceEquipmentArchivesHandle {

    @Resource
    private TSbazddMapper tSbazddMapper;

    @Resource
    private TSbcjMapper tSbcjMapper;

    @Resource
    private TSblxMapper tSblxMapper;

    @Resource
    private TWxsbMapper tWxsbMapper;

    @Resource
    private TXzqhMapper tXzqhMapper;



    /**
     * 保存清洁取暖数据设备档案
     * @param bo 清洁取暖设备档案业务模型
     */
    @CtceTransactional
    public String saveEquipmentArchives(CtceEquipmentArchivesBo bo) throws Exception {
        String ddId = bo.getLocationId();

        // 判断是否可以编辑数据
        String dateString = new SimpleDateFormat("yyyy-MM-dd").format(bo.getAzsj());
        String year = new SimpleDateFormat("yyyy").format(bo.getAzsj());
        for (DeviceSaveBo deviceSaveBo : bo.getDeviceSaveBos()) {
            //判断是否封账
            if (isLockInstall(bo.getAreacode(), dateString, deviceSaveBo.getManufacturerId(), year, "")) {
                throw new BusinessException("系统封账中,请稍后再试");
            }
        }

        // 身份证号没有加密，且符合行政区划要求进行身份证号验证
        if (!bo.getIdcard().contains("*")) {
            if (StrUtil.isNotEmpty(bo.getAreacode()) && (bo.getAreacode().startsWith("110116") || bo.getAreacode()
                    .startsWith("110129") || bo.getAreacode().startsWith("3701"))) {
                List<TSbazdd> existTSbazdds = tSbazddMapper.findTsbazddListByIdCardNo(bo.getIdcard());
                if (CollUtil.isNotEmpty(existTSbazdds)) {
                    throw new BusinessException("当前身份证号已经安装,请更换身份证");
                }
            }
        }

        // 延庆需要验证电表号或客户编号也不能重复
        if (StrUtil.isNotEmpty(bo.getAreacode()) && bo.getAreacode().startsWith("110129")) {
            boolean hasDuplicateKhbhOrDbh = hasDuplicateKhbhOrDbh(bo);
            if (hasDuplicateKhbhOrDbh) {
                throw new BusinessException("电表号或者客户编号已存在!");
            }
        }

        if (StrUtil.isBlank(ddId)) {
            // 新增
            ddId = bo.getAreacode().substring(0, 12) + getKey("azdd");
            bo.setLocationId(ddId);
            addEquipmentArchives(bo);
        } else {
            // 编辑
            editEquipmentArchives(bo);
        }
        return ddId;
    }

    /**
     * 存在重复的号码
     * @return
     */
    private boolean hasDuplicateKhbhOrDbh(CtceEquipmentArchivesBo bo) throws Exception {
        if (StrUtil.isEmpty(bo.getKhbh()) && StrUtil.isEmpty(bo.getDbh())) {
            return false;
        }
        String xzqhdm = bo.getAreacode().substring(0, 6);

        int result = tSbazddMapper.hasDuplicateNo(bo.getDbh(), bo.getLocationId(), xzqhdm);
        if (result > 0) {
            return true;
        }
        result = tSbazddMapper.hasDuplicateNo(bo.getKhbh(), bo.getLocationId(), xzqhdm);
        if (result > 0) {
            return true;
        }

        return false;
    }


    /**
     * 编辑设备档案
     * @param bo
     */
    private void editEquipmentArchives(CtceEquipmentArchivesBo bo) throws Exception {
        // todo 已审核数据，不能修改


        // 先删除数据
        deleteEquipmentArchives(bo);
        // 再新增数据
        saveEquipmentInsall(bo, true);
    }

    /**
     * 新增设备档案
     * @param bo
     */
    private void addEquipmentArchives(CtceEquipmentArchivesBo bo) throws Exception {

        // 保存设备安装数据
        saveEquipmentInsall(bo, false);

        // 更新施工计划
        // tSbsgjhMapper.updateById(TSbsgjh.builder().id(bo.getPlanId()).ddId(bo.getLocationId()).build());

    }

    /**
     * 保存设备安装信息
     * @param bo
     */
    private void saveEquipmentInsall(CtceEquipmentArchivesBo bo, boolean update) throws Exception {
        int i = 1;
        for (DeviceSaveBo deviceSaveBo : bo.getDeviceSaveBos()) {
            final String xtlx;
            final String sfcysb;
            switch (deviceSaveBo.getDeviceTypeId()) {
                case "22":
                    xtlx = "WD";
                    sfcysb = "1";
                    break;
                case "23":
                    xtlx = "DB";
                    sfcysb = "1";
                    break;
                default:
                    xtlx = "CTCE";
                    sfcysb = "0";
            }
            TSbazdd tSbazdd = new TSbazdd();
            BeanUtils.copyProperties(bo, tSbazdd);
            tSbazdd.setDdId(bo.getLocationId());
            tSbazdd.setXyId(bo.getInstallProtocolId());
            tSbazdd.setXxdz(bo.getAddress());
            tSbazdd.setSsxzqh(bo.getAreacode());
            tSbazdd.setHzxm(bo.getMainname());
            tSbazdd.setSfzh(DESUtils.encrypt(bo.getIdcard(), Globals.DESKEY));
            tSbazdd.setLxdd(bo.getPhone());
            tSbazdd.setJzmj(bo.getBuildingArea());
            tSbazdd.setJzjg(bo.getBuildingstructure());
            tSbazdd.setWqhd(new BigDecimal(bo.getWallthickness()));
            tSbazdd.setWqbw(bo.getKeepwarm());
            tSbazdd.setJzazwz(bo.getInstallposition());
            tSbazdd.setJd(bo.getJd());
            tSbazdd.setWd(bo.getWd());
            tSbazdd.setCnmd(bo.getCnmd());
            tSbazdd.setFwcx(Integer.valueOf(bo.getFwcx()));
            tSbazdd.setChlx(Integer.valueOf(bo.getChlx()));
            tSbazdd.setByd1(new Date());
            tSbazdd.setAzrq(bo.getAzsj());
            tSbazdd.setSynymc("");
            tSbazdd.setZjazqk("已安装");
            tSbazdd.setGxazqk("已安装");
            tSbazdd.setCnmdzt("已有");
            tSbazdd.setPztd("已完成");
            tSbazdd.setDltjzb("已完成");
            tSbazdd.setSgzbsh("通过");
            tSbazdd.setTsyh("正常");
            tSbazdd.setSjsfsc("是");
            tSbazdd.setJlqk("通过");
            tSbazdd.setSgjdsh("通过");
            tSbazdd.setSbazsj(bo.getOperateDate());
            tSbazdd.setSjtfilename("");
            tSbazdd.setSjtpath(bo.getDesignImg());
            tSbazdd.setPmtpath("");
            tSbazdd.setPmtpath(bo.getPlaneImg());
            tSbazdd.setAztfilename1("");
            tSbazdd.setAztpath1(bo.getAztpath1());
            tSbazdd.setAztfilename2("");
            tSbazdd.setAztpath2(bo.getAztpath2());
            tSbazdd.setAztfilename3("");
            tSbazdd.setAztpath3(bo.getAztpath3());
            tSbazdd.setAztfilename4("");
            tSbazdd.setAztpath4(bo.getAztpath4());
            tSbazdd.setAztfilename5("");
            tSbazdd.setAztpath5(bo.getAztpath5());
            tSbazdd.setAztfilename6("");
            tSbazdd.setAztpath6(bo.getAztpath6());
            tSbazdd.setLrr(bo.getOperatePlatform() + "-" + bo.getOperateUserId());
            tSbazdd.setLastModified(bo.getOperateDate());
            tSbazdd.setSfcz("02");
            tSbazdd.setGnqy("03");
            tSbazdd.setMjsfxfQ("是");
            tSbazdd.setCssfzbQ("是");
            tSbazdd.setSbsfzbQ("是");
            tSbazdd.setSbsfxfQ("是");
            tSbazdd.setSfsfxf("是");
            tSbazdd.setSfyhdtQ("是");
            tSbazdd.setSfazQ("是");
            tSbazdd.setZlsfqqQ("是");
            tSbazdd.setShysqkQ("0");
            tSbazdd.setShyssjQ(new Date());
            tSbazdd.setShysrQ("");
            tSbazdd.setCzyhQ("");
            tSbazdd.setZbnf("");
            tSbazdd.setYhzt(0);
            tSbazdd.setDbh(bo.getDbh());
            tSbazdd.setMjsfxf("是");
            tSbazdd.setCssfzb("是");
            tSbazdd.setSbsfzb("是");
            tSbazdd.setSbsfxf("是");
            tSbazdd.setSfsfxf("是");
            tSbazdd.setSfyhdt("是");
            tSbazdd.setSfaz("是");
            tSbazdd.setZlsfqq("是");
            tSbazdd.setXh(i);
            tSbazdd.setXtlx(xtlx);
            tSbazdd.setShysqk("");
            tSbazdd.setCnmj(bo.getHeatingArea());
            TSbcj tSbcj = tSbcjMapper.selectById(deviceSaveBo.getManufacturerId());
            if (ObjectUtil.isNull(tSbcj)) {
                throw new IllegalBusinessException("设备厂家错误");
            }
            String manufactureName = tSbcj.getGsmc();
            tSbazdd.setSbpp(manufactureName);
            tSbazdd.setJldw(manufactureName);
            tSbazdd.setSbId(deviceSaveBo.getSbId());
            tSbazdd.setSbLxid(deviceSaveBo.getDeviceModelId());
            // DTU号不为空，绑定DTU
            if (StrUtil.isNotEmpty(deviceSaveBo.getDtuId())) {
                tSbazdd.setWxId(deviceSaveBo.getDtuId());
                // 更新t_wxsb，建立绑定关系
                tWxsbMapper.bindDtu(tSbazdd.getDdId(), tSbazdd.getSbId(), deviceSaveBo.getDtuId(), deviceSaveBo.getDeviceSerialNo());
            }
            TSblx tSblx = tSblxMapper.findSblx(deviceSaveBo.getDeviceModelId());
            if (ObjectUtil.isNull(tSblx)) {
                throw new IllegalBusinessException("设备型号错误");
            }
            tSbazdd.setSbxh(tSblx.getSbxh());
            tSbazdd.setYnfsdl(tSblx.getYnfsdl());
            tSbazdd.setYnfsxl(tSblx.getYnfsxl());
            tSbazdd.setSyny(deviceSaveBo.getDeviceTypeId());
            tSbazdd.setBz(deviceSaveBo.getDeviceSerialNo());
            tSbazdd.setFwjs(bo.getFwjs());
            tSbazdd.setFwyt(bo.getFwyt());
            tSbazdd.setSjdw(bo.getSjdw());
            tSbazdd.setTzbh(bo.getTzbh());
            tSbazdd.setSfcysb(sfcysb);
            tSbazdd.setCycnmj(bo.getCycnmj());
            tSbazdd.setSfnc(bo.getSfnc());
            tSbazdd.setGnfs(bo.getGnfs());
            tSbazdd.setYnztxz(bo.getYhztxz());
            tSbazdd.setAzry(bo.getAzry());
            tSbazdd.setAzrydh(bo.getAzrydh());
            tSbazdd.setMph(bo.getMph());
            tSbazdd.setByn3(bo.getGzzj());
            tSbazdd.setKhbh(bo.getKhbh());
            tSbazdd.setCgly(StrUtil.emptyToDefault(bo.getCgly(), "计划内采购"));
            tSbazdd.setJzcg(bo.getBuildingHeight());
            if (NumberUtil.isInteger(bo.getZbnf())) {
                tSbazdd.setZbnf(bo.getZbnf());
                LocalDateTime zbrq = LocalDateTime.of(LocalDateTime.now()
                        .getYear() + Integer.parseInt(bo.getZbnf()), 3, 31, 23, 59, 59);
                tSbazdd.setZbrq(Date.from(zbrq.atZone(ZoneId.systemDefault()).toInstant()));
            }
            if (Objects.equals(bo.getAzzt(), "13")) {
                tSbazdd.setShrydh("1");
            }
            setInstallStatus(bo, tSbazdd);


            i++;
            if (update) {
                tSbazddMapper.updateById(tSbazdd);
            } else {
                tSbazddMapper.insert(tSbazdd);
            }
        }
    }

    /**
     * 是否封账
     * @param ssxzqh 行政区划
     * @param azrq   安装日期
     * @param gsdm   公司代码
     * @param pc     安装日期年份
     * @return
     */
    public boolean isLockInstall(String ssxzqh, String azrq, String gsdm, String pc,
            String locationid) throws Exception {
        if (StrUtil.isNotEmpty(locationid)) {
            // 已安装设备，审核通过，不可修改
            int count = tSbazddMapper.selSqyhqk(locationid);
            if (count > 0) {
                return true;
            }
        }
        int i = 0;
        boolean result = false;
        i = tSbazddMapper.lock1(gsdm, ssxzqh, getYear(azrq));
        if (i > 0) {
            result = false;
        } else {
            String xzqh = ssxzqh.substring(0, 2);
            if ("37".equals(xzqh)) { // 山东省
                i = tSbazddMapper.lock2(ssxzqh, pc);
            } else { // 其他省
                i = tSbazddMapper.lock2(ssxzqh, getYear(azrq));
            }
            if (i > 0) {
                return true;
            }

        }
        return result;
    }

    /**
     * 设置安装状态
     * @param bo
     * @param tSbazdd
     */
    private static void setInstallStatus(CtceEquipmentArchivesBo bo, TSbazdd tSbazdd) {
        String ztbs = bo.getAzzt();

        if (StrUtil.isNotEmpty(bo.getAztpath1()) || StrUtil.isNotEmpty(bo.getAztpath2()) || StrUtil.isNotEmpty(bo.getAztpath3()) || StrUtil.isNotEmpty(bo.getAztpath4()) || StrUtil.isNotEmpty(bo.getAztpath5()) || StrUtil.isNotEmpty(bo.getAztpath6())) {
            ztbs = "13";
        }
        if (StrUtil.isNotEmpty(bo.getDesignImg()) && StrUtil.isNotEmpty(bo.getPlaneImg()) && ztbs.equals("11")) {
            ztbs = "12";
        }

        tSbazdd.setZtbs(ztbs);
    }

    /**
     * 删除设备档案
     * @param bo
     */
    private void deleteEquipmentArchives(CtceEquipmentArchivesBo bo) throws Exception {
        // 解绑dtu
        List<TSbazdd> tsbazddList = tSbazddMapper.findTsbazddList(bo.getLocationId());
        Map<String, String> deviceBindDtuMap = new HashMap<>();
        for (TSbazdd tSbazdd : tsbazddList) {
            deviceBindDtuMap.put(tSbazdd.getSbId(), tSbazdd.getWxId());
        }
        for (DeviceSaveBo deviceSaveBo : bo.getDeviceSaveBos()) {
            String dtuId = deviceBindDtuMap.get(deviceSaveBo.getSbId());
            // 设备已绑定DTU， 但是前端又不传DTUID的，解绑DTU
            if (StrUtil.isNotBlank(dtuId) && StrUtil.isBlank(deviceSaveBo.getDtuId())) {
                tWxsbMapper.unBindDtu(dtuId);
            }

            // 前端标识删除的设备，删除运营的设备数据，并将解绑DTU
            if (StrUtil.isNotEmpty(bo.getLocationId())) {
                // 删除运营平台设备数据
                tSbazddMapper.syncDeletedEquipmentOfOpe(deviceSaveBo.getSbId());
                // 解绑DTU
                tWxsbMapper.unBindDtu(deviceSaveBo.getDtuId());
            }
        }
    }

    /**
     * 获取年份
     * @param date 日期
     * @return
     */
    public static String getYear(Date date) {
        return getYear(date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate());
    }

    /**
     * 获取年份
     * @param dateStr 日期字符串，格式：yyyy-MM-dd
     * @return
     */
    public static String getYear(String dateStr) {
        return getYear(LocalDate.parse(dateStr, DateTimeFormatter.ofPattern("yyyy-MM-dd")));
    }

    /**
     * 获取年份
     * @param localDate 日期
     * @return
     */
    public static String getYear(LocalDate localDate) {
        // 小于等于3月20日，年份减一
        if (localDate.getMonthValue() < 3 || (localDate.getMonthValue() == 3 && localDate.getDayOfMonth() <= 20)) {
            return String.valueOf(localDate.getYear() - 1);
        }
        return String.valueOf(localDate.getYear());
    }

    /**
     * 获取清洁取暖主键ID
     * @param type 类型
     * @return
     */
    public String getKey(String type) throws Exception {
        String key = "";
        int value = 0;
        if (type.equals("azdd")) {
            value = tSbazddMapper.getPrimaryKey("SEQ_SBAZDD");
            key = String.format("%0" + 8 + "d", value);
        }
        return key;
    }


    public PersonalProjectDetailsDto getPersonalProjectDeatils(String sbId) throws Exception {
        PersonalProjectDetailsDto dto = new PersonalProjectDetailsDto();
        TSbazdd queryTSbazdd = new TSbazdd();
        queryTSbazdd.setSbId(sbId);
        TSbazdd tSbazdd = tSbazddMapper.selectOne(new LambdaQueryWrapper<>(queryTSbazdd));
        dto.setInstallProtocolId(tSbazdd.getXyId());
        dto.setLocationId(tSbazdd.getDdId());
        dto.setCustomerDetailsDto(convertToCustomerDeatilsDto(tSbazdd));
        dto.setInstallDetailsDto(convertToInstallDetailsDto(tSbazdd));
        dto.setBuildingDetailsDto(convertToBuildingDetailsDto(tSbazdd));
        dto.setDeviceDetailsDtos(convertToDeviceDetailsDto(tSbazdd));
        dto.setImageDetailsDto(convertToImageDetailsDto(tSbazdd));
        return dto;
    }

    private List<DeviceDetailsDto> convertToDeviceDetailsDto(TSbazdd tSbazdd) {
        List<DeviceDetailsDto> list = tSbazddMapper.getDeviceList(tSbazdd.getDdId());
        return list;
    }

    private BuildingDetailsDto convertToBuildingDetailsDto(TSbazdd tSbazdd) {
        BuildingDetailsDto buildingDetailsDto = new BuildingDetailsDto();
        buildingDetailsDto.setSfnc(tSbazdd.getSfnc());
        buildingDetailsDto.setHeatingArea(tSbazdd.getCnmj());
        buildingDetailsDto.setBuildingArea(tSbazdd.getJzmj());
        buildingDetailsDto.setCycnmj(tSbazdd.getCycnmj());
        buildingDetailsDto.setBuildingStructure(tSbazdd.getJzjg());
        buildingDetailsDto.setBuildingHeight(ObjectUtil.isNull(tSbazdd.getJzcg()) ? null : tSbazdd.getJzcg());
        buildingDetailsDto.setOuterWallThickness(String.valueOf(tSbazdd.getWqhd().intValue()));
        buildingDetailsDto.setOuterWallKeepWarm(tSbazdd.getWqbw());
        buildingDetailsDto.setGnfs(tSbazdd.getGnfs());
        buildingDetailsDto.setInstallPosition(tSbazdd.getJzazwz());
        buildingDetailsDto.setFwyt(tSbazdd.getFwyt());
        buildingDetailsDto.setFwjs(tSbazdd.getFwjs());
        buildingDetailsDto.setSjdw(tSbazdd.getSjdw());
        buildingDetailsDto.setTzbh(tSbazdd.getTzbh());
        buildingDetailsDto.setChlx(ObjectUtil.isNull(tSbazdd.getChlx()) ? null : tSbazdd.getChlx().toString());
        buildingDetailsDto.setSjrfh(tSbazdd.getSjrfh());
        buildingDetailsDto.setFwcx(ObjectUtil.isNull(tSbazdd.getFwcx()) ? null : tSbazdd.getFwcx().toString());
        buildingDetailsDto.setMdgzzt(tSbazdd.getSfcz());
        buildingDetailsDto.setCnmd(tSbazdd.getCnmd());
        return buildingDetailsDto;
    }

    private ImageDetailsDto convertToImageDetailsDto(TSbazdd tSbazdd) {
        ImageDetailsDto imageDetailsDto = new ImageDetailsDto();
        imageDetailsDto.setDesignImg(tSbazdd.getSjtpath());
        imageDetailsDto.setDesignImgUrls(StrUtil.isEmpty(tSbazdd.getSjtpath()) ? Collections.emptyList() : Collections.singletonList(OssUtil.getImgSignURL(tSbazdd.getSjtpath(), 1)));
        imageDetailsDto.setPlanImg(tSbazdd.getPmtpath());
        imageDetailsDto.setPlanImgUrls(StrUtil.isEmpty(tSbazdd.getPmtpath()) ? Collections.emptyList() : Collections.singletonList(OssUtil.getImgSignURL(tSbazdd.getPmtpath(), 1)));
        imageDetailsDto.setAztpath1(tSbazdd.getAztpath1());
        imageDetailsDto.setAztpath1Urls(StrUtil.isEmpty(tSbazdd.getAztpath1()) ? Collections.emptyList() : Collections.singletonList(OssUtil.getImgSignURL(tSbazdd.getAztpath1(), 1)));
        imageDetailsDto.setAztpath2(tSbazdd.getAztpath2());
        imageDetailsDto.setAztpath2Urls(StrUtil.isEmpty(tSbazdd.getAztpath2()) ? Collections.emptyList() : Collections.singletonList(OssUtil.getImgSignURL(tSbazdd.getAztpath2(), 1)));
        imageDetailsDto.setAztpath3(tSbazdd.getAztpath3());
        imageDetailsDto.setAztpath3Urls(StrUtil.isEmpty(tSbazdd.getAztpath3()) ? Collections.emptyList() : Collections.singletonList(OssUtil.getImgSignURL(tSbazdd.getAztpath3(), 1)));
        imageDetailsDto.setAztpath4(tSbazdd.getAztpath4());
        imageDetailsDto.setAztpath4Urls(StrUtil.isEmpty(tSbazdd.getAztpath4()) ? Collections.emptyList() : Collections.singletonList(OssUtil.getImgSignURL(tSbazdd.getAztpath4(), 1)));
        imageDetailsDto.setAztpath5(tSbazdd.getAztpath5());
        imageDetailsDto.setAztpath5Urls(StrUtil.isEmpty(tSbazdd.getAztpath5()) ? Collections.emptyList() : Collections.singletonList(OssUtil.getImgSignURL(tSbazdd.getAztpath5(), 1)));
        imageDetailsDto.setAztpath6(tSbazdd.getAztpath6());
        imageDetailsDto.setAztpath6Urls(StrUtil.isEmpty(tSbazdd.getAztpath6()) ? Collections.emptyList() : Collections.singletonList(OssUtil.getImgSignURL(tSbazdd.getAztpath6(), 1)));
        return imageDetailsDto;
    }

    /**
     * 转换为安装信息
     * @param tSbazdd
     * @return
     */
    private InstallDetailsDto convertToInstallDetailsDto(TSbazdd tSbazdd) {
        InstallDetailsDto installDetailsDto = new InstallDetailsDto();
        installDetailsDto.setAzry(tSbazdd.getAzry());
        installDetailsDto.setAzrydh(tSbazdd.getAzrydh());
        installDetailsDto.setAzsj(tSbazdd.getAzrq());
        installDetailsDto.setAzzt(tSbazdd.getZtbs());
        installDetailsDto.setCgly(tSbazdd.getCgly());
        installDetailsDto.setGzzj(tSbazdd.getByn3());
        installDetailsDto.setZbnf(tSbazdd.getZbnf());
        return installDetailsDto;
    }

    /**
     * 转换为用户信息
     * @param tSbazdd
     * @return
     */
    private CustomerDetailsDto convertToCustomerDeatilsDto(TSbazdd tSbazdd) throws Exception {
        CustomerDetailsDto customerDetailsDto = new CustomerDetailsDto();
        customerDetailsDto.setIdCardNo(DESUtils.decrypt(tSbazdd.getSfzh(), Globals.DESKEY));
        customerDetailsDto.setWd(tSbazdd.getWd());
        customerDetailsDto.setJd(tSbazdd.getJd());
        customerDetailsDto.setAddress(tSbazdd.getXxdz());
        customerDetailsDto.setMasterName(tSbazdd.getHzxm());
        customerDetailsDto.setPhone(tSbazdd.getLxdd());
        customerDetailsDto.setAreaCode(tSbazdd.getSsxzqh());
        customerDetailsDto.setMph(tSbazdd.getMph());
        customerDetailsDto.setYhztxz(tSbazdd.getYnztxz());
        customerDetailsDto.setKhbh(tSbazdd.getKhbh());
        customerDetailsDto.setDbh(tSbazdd.getDbh());
        customerDetailsDto.setAreaCodeName(tXzqhMapper.getAreaInfo(tSbazdd.getSsxzqh()).getXzqhmc());
        return customerDetailsDto;
    }

}
